/**
	
		File: js/script.js
		
		Author: Sasa Milojevic
				milojevic.sasa@gmail.com
		
		Date: 2012-03-21 
	
*/


/**
 * 	Document ready jQuery  
 */

	
$(function(){
	
    /** 
     *  jQuery FILEUPLOAD
     *  
     *  Sluzi za jQuery upload slike sa mogucnoscu da se slika nakon uploada odmah prikaze na stranici
     *  U header se ukljucuje: 
        <!-- Ajax Upload -->
        <script src="<?=base_url()?>js/jQueryUpload/jquery.ui.widget.js"></script>
        <script src="<?=base_url()?>js/jQueryUpload/jquery.iframe-transport.js"></script>
        <script src="<?=base_url()?>js/jQueryUpload/jquery.fileupload.js"></script>
        
     *  HTML view:
        <!-- Dugme za file browse i upload. data-url je skript koji obradjuje upload --> 
        <input type="file" class="fileupload" data-url="<?=base_url()?>administration/ajax/upload_image/img/uploads" name="img" id="upload_img" class="ui-widget-content ui-corner-all" /> 
        
        <!-- Input polje u koje se upisuje file name uploadovane slike -->
        <input type="hidden" name="data[img]" id="img" value="" />
  
        <!-- Div za prikaz rezultata uploada -->
        <div id="upload_result" class="hide"></div> 
     
     *  'data-url' atribut u input file polju sadrzi:
     *              1. putanju do funkcije koji vrsi upload ( <?=base_url()?>administration/ajax/upload_image )
     *              2. parametre funkcije, koji definisu naziv input polja gde ce se upisati 
     *                 naziv slike (img) i 
     *                 naziv foldera gde ce biti uploadovana slika ( uploads/images/img )
     *                 u odnosu na root sajta. 
     *                 Root je definisan u config.php
     *                 $config['base_dir'] = ...
     *     
     *
     */
    $('.fileupload').fileupload({
        dataType: 'json',
        start: function(){                
            $('#wait').show(); // Prikazi wait gif
        },            
        done: function (e, data) {
            $('#wait').hide(); // Sakrij wait gif
            var html = "";

            if (data.result.status == 1){ // Ako je uspesno uradjen upload
                html += data.result.html; // rezultat HTML dodaj divu rezultata
                $('#gallery_items').show().html(html); // prikazi rezultat uploada
                //$('#'+data.result.field_name).val(data.result.file_name); // upisi ime file-a u input hide polje
                //$( this ).attr('disabled',true); // Iskljuci browse dugme
            }
            else {// Ako dodje do greske 
                html += data.result.msg; // Preuzmi tekst greske
                $('#response').show().html(html); // prikazi tekst greske u div rezultata
            }
        }
    });
    
    
    // jQuery UI Slider
    $( "#slider-range" ).slider({
        range: true,
        min: 18,
        max: 99,
        values: [ 25, 55 ],
        slide: function( event, ui ) {
              $( "#amount" ).val(  ui.values[ 0 ] + " - " + ui.values[ 1 ] );
        }
    });
    
    $( "#amount" ).val(  $( "#slider-range" ).slider( "values", 0 ) +
          " - " + $( "#slider-range" ).slider( "values", 1 ) );
    
    
    $('#message').keyup(
      function(){        
        var message = $('#message').val();
        var message_lenght = message.length; // Ukupna duzina poruke
        var count =  Math.ceil( message_lenght / MESSAGE_LEN )-1;
        var num_left = MESSAGE_LEN - (message_lenght - count*MESSAGE_LEN);
        var price = MESSAGE_PRICE * (count+1);
        if( 0 == price ) price = MESSAGE_PRICE;
        if(  count == -1 ) num_left = MESSAGE_LEN;
        $('#message_price').html(price);
        $('#num_caracters').html(num_left);       
      }
    );
      
    $('#send_message').click(
      function(){
        var message = $('#message').val();
        var to = $('#to_id').val();
        if( message.length == 0 ) return false;
        
        var ajaxURL = BASE_URL + 'conversation/send_message';
    
        // Ajax upit
        $.ajax({  
            type: "POST", 
            url: ajaxURL,
            data: 'to='+to+'&message='+message,
            cache: false,
            async: false,
            success: function(response){

                var parsed = JSON.parse(response);
                var html = '';

                if(parseInt(parsed.ind) == 1)
                {                    
                    html += parsed.html; // rezultat HTML 
                    $('#messages_list').html(html); // prikazi rezultat 
                    // Obrisi text box i postavi brojac i cenu
                    $('#message').val('')
                    $('#message_price').html(MESSAGE_PRICE);
                    $('#num_caracters').html(MESSAGE_LEN);       
                }
                else
                {      
                    html += "<p>"+parsed.msg +"</p>";
                    $('#response').show().html(html).delay(2500).hide(500); 
                }            
            }  
        }); // end AJAX upita
        
      }
    );
    
    $('#send_support_message').click(
      function(){
        var message = $('#message').val();
        //var to = $('#to_id').val();
        if( message.length == 0 ) return false;
        
        var ajaxURL = BASE_URL + 'support/send_support_message';
    
        // Ajax upit
        $.ajax({  
            type: "POST", 
            url: ajaxURL,
            data: 'message='+message,
            cache: false,
            async: false,
            success: function(response){

                var parsed = JSON.parse(response);
                var html = '';

                if(parseInt(parsed.ind) == 1)
                {                    
                    html += parsed.html; // rezultat HTML 
                    $('#messages_list').html(html); // prikazi rezultat 
                    // Obrisi text box i postavi brojac i cenu
                    $('#message').val('')
                    //$('#message_price').html(MESSAGE_PRICE);
                    //$('#num_caracters').html(MESSAGE_LEN);       
                }
                else
                {      
                    html += "<p>"+parsed.msg +"</p>";
                    $('#response').show().html(html).delay(2500).hide(500); 
                }            
            }  
        }); // end AJAX upita
        
      }
    );
      
    $("#submit_search").click(
      function(){
        
        var filter = $("#filter_form").serialize();
        
        var ajaxURL = BASE_URL + 'search/getSearchResult';
         $("#submit_search").attr('disabled',true);
        // Ajax upit
        $.ajax({  
            type: "POST", 
            url: ajaxURL,
            data: filter,
            cache: false,
            async: false,
            success: function(response){

                var parsed = JSON.parse(response);
                var html = '';

                if(parseInt(parsed.ind) == 1)
                {                    
                    html += parsed.html; // rezultat HTML 
                    $('#search_results').html(html);       
                }
                else
                {      
                    html += "<p>"+parsed.msg +"</p>";
                    $('#search_results').html(html); 
                }            
            }  
        }); // end AJAX upita
        $("#submit_search").attr('disabled',false);
      }
    );
      
   $("#zip-code-search").click(
    function(){
      $("#form-zip-code").submit();
    }
   );
     
   $("#home-serach-submit").click(
    function(){
      $("#form-home-search").submit();
    }
   );
      
   $(".order").click(
    function(){
      var value = $(this).attr('alt');
      $('#'+value).attr('checked', true);      
      //$("#payment-form").submit();
    }
   );
     
   
   $( "#accordion" ).accordion({
            heightStyle: "content"
    });
    
    
   // Present list
  $( "#selectable" ).selectable({
    stop: function() {
      var result = $( "#select-result" ).empty();
      $( ".ui-selected", this ).each(function() {
        var index = $( "#selectable li" ).index( this );
        result.append( " #" + ( index + 1 ) );
      });
    }
  });
  
  $(".group1").colorbox({rel:'group1'});
//  $('.group1').on('click', function(){
//        $.colorbox({
//            //open:true,
//            //href: this.href
//            rel: group1
//            //plus any other interesting options    
//        });
//
//        return false;
//    });
  $(".iframe").colorbox({ width:"525px", height:"420px"});
  
  
////////////////////////////////////////////////////////////////////////////////
//    SEARCH BOX
////////////////////////////////////////////////////////////////////////////////
// Search Friend
  $("#search_friend").click(
    function(){
      
      var name = $("#input_search_friend").val();
      
      if( name != "" )
        search_friend(name);
      
    }
  );
    
    $("#search_favorite").click(
    function(){
      
      var name = $("#input_search_favorite").val();
      
      if( name != "" )
        search_favorite(name);
      
    }
  );
  
  
  // PROMO CODE
  $("#promo_code_submit").click(
    function(){
      
      var code = $("#promo_code").val();
      var ajaxURL = BASE_URL + 'profile/accept_promo_code';
         $("#promo_code_submit").attr('disabled',true);
        // Ajax upit
        $.ajax({  
            type: "POST", 
            url: ajaxURL,
            data: "code="+code,
            cache: false,
            async: false,
            success: function(response){

                var parsed = JSON.parse(response);
                var html = '';

                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
                
                if(parsed.ind == 1)
                  location.replace( BASE_URL + "profile.htm" );
            }  
        }); // end AJAX upita
        $("#promo_code_submit").attr('disabled',false);
      
      
    }
  );
    
  
  $( "#contact-form" ).validate({
        rules: {
            // simple rule, converted to {required:true}
            'contact[name]'   : "required", 
            'contact[email]'  : "required email", //
            'contact[message]': "required"
        
        },
        messages:{
            'contact[name]'    : "Pflichtfeld",
            'contact[email]'   : "Bitte füge die richtige Emailadresse ein.",
            'contact[message]' : "Pflichtfeld"
        },
        submitHandler: function() {                                     
            send_contact();
        },
        invalidHandler: function() { } 
    });
  
  
  $("#contact-submit").click(
    function(){
      $("#contact-form").submit();
    }
  );
  
}); // End Document ready


function send_contact()
{
  //alert('Send');
  var name = $("#contact_name").val();
  var email = $("#contact_email").val();
  var message = $("#contact_message").val();
  
  if( name !="" && email != "" && message != "" )
  {
    var contact_data = $("#contact-form").serialize();
    var ajaxURL = CONTROLLER_URL + 'send_contact';

    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: contact_data,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';
            
            html += "<p>"+parsed.msg +"</p>";
            $('#response').show().html(html).delay(2500).hide(500); 
            if( parseInt(parsed.ind) == 1 )
            {
                $("#contact_name").val('');
                $("#contact_email").val('');
                $("#contact_message").val('');
            }
                      
        }  
    }); // end AJAX upita
   
  }  
}

function inline_edit(field)
{
    var item = $("#edit_"+field);
    var data = item.val();
    
    var ajaxURL = BASE_URL + 'profile/edit_item';
    
        // Ajax upit
        $.ajax({  
            type: "POST", 
            url: ajaxURL,
            data: 'field='+field+'&data='+data,
            cache: false,
            async: false,
            success: function(response){

                var parsed = JSON.parse(response);
                var html = '';

                if(parseInt(parsed.ind) == 1)
                {
                    item.replaceWith(data);
                }
                else
                {      
                    html += "<p>"+parsed.msg +"</p>";
                    $('#response').show().html(html).delay(2500).hide(500); 
                }            
            }  
        }); // end AJAX upita
    
   
    
}

function edit_item(field)
{
    var html = "<input type='text' class='inline-edit' id='edit_"+field+"' onchange=\"inline_edit('"+field+"')\" />";
    var item = $("#link_edit_"+field);    
    item.replaceWith(html);
}


function lock_unlock_img(image_id)
{
        
    var ajaxURL = BASE_URL + 'ajax/lock_unlock_img';
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+image_id,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#gallery_items').html(html); // prikazi rezultat 
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}


function delete_img(id)
{    
    var ajaxURL = BASE_URL + 'ajax/delete_img';
        
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+id, // image id
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#gallery_items').html(html); // prikazi rezultat 
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}

function set_profile_img(id)
{
    var ajaxURL = BASE_URL + 'ajax/set_profile_img';
       
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+id, // image id
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                //html += parsed.html; // rezultat HTML 
                //$('#gallery_items').show().html(html); // prikazi rezultat 
                //Izmeni slike
                var src_thumb = BASE_URL + 'profile/image/thumb/'+parsed.main_image;
                var src_small = BASE_URL + 'profile/image/small/'+parsed.main_image;
                $('#profile-thumb').attr('src',src_thumb);
                $('#profile-image').attr('src',src_small);
                
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}


function add_favorite(favorite_id)
{
    var ajaxURL = BASE_URL + 'favorites/add_favorite';
       
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+favorite_id, // favorite id
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                //$('#favorites_list').html(html); // prikazi rezultat 
                //$('#num_favorites').html(parsed.num_favorites);
                $('#my_favorites').html(parsed.my_favorites_html);
                $('#profile-side-menu').html(parsed.side_menu_html);
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}

function remove_favorite(favorite_id)
{
    var ajaxURL = BASE_URL + 'favorites/remove_favorite';
       
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+favorite_id, // favorite id
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#favorites_list').html(html); // prikazi rezultat 
                $('#num_favorites').html(parsed.num_favorites);
                $('#my_favorites').html(parsed.my_favorites_html);
                $('#profile-side-menu').html(parsed.side_menu_html);
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}


function remove_friend(friend_id)
{
    var ajaxURL = BASE_URL + 'friends/remove_friend';

    //$("#dialog-confirm").dialog("close");
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+friend_id, // friend id
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#friends_list').html(html); // prikazi rezultat 
                $('#num_friends').html(parsed.num_friends);
                $('#my_friends').html(parsed.my_friends_html);                
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}



function add_friend(friend_id)
{
    var ajaxURL = BASE_URL + 'friends/add_friend';
    
    //$("#dialog-confirm").dialog("close");
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+friend_id, // friend id
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#friends_list').html(html); // prikazi rezultat 
                $('#num_friends').html(parsed.num_friends);
                $('#my_friends').html(parsed.my_friends_html);
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}

function send_friend_request(friend_id)
{
    var ajaxURL = BASE_URL + 'friends/send_friend_request';
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+friend_id, // friend id
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';
            if( parsed.ind == -2 )
            {
              html += "<p>"+parsed.msg +"</p>";
              $('#response').show().html(html).delay(5000).hide(500);               
            }
            else
            {
              html += "<p>"+parsed.msg +"</p>";
              $('#response').show().html(html).delay(2500).hide(500); 
            }
                    
        }  
    }); // end AJAX upita
}

function send_poke(poke_id,user_id) // kome, od koga
{
    var ajaxURL = BASE_URL + 'pokes/send_poke';
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'poke_id='+poke_id+"&user_id="+user_id, 
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';
           if(parseInt(parsed.ind) == 1)
            {
                html = parsed.html; // rezultat HTML 
                $('#pokes_list').html(html); // prikazi rezultat 
                
                html = "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500);
                update_right_part_menu();
            }
            else
            {      
                html = "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }       
                    
        }  
    }); // end AJAX upita
}


function remove_poke(id)
{
    var ajaxURL = BASE_URL + 'pokes/remove_poke';
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'id='+id, 
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';
           if(parseInt(parsed.ind) == 1)
            {
                html = parsed.html; // rezultat HTML 
                $('#pokes_list').html(html); // prikazi rezultat 
                
                html = "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500);
                update_right_part_menu();
            }
            else
            {      
                html = "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }       
                    
        }  
    }); // end AJAX upita
}

function remove_conversation(from_id,to_id)
{
    var ajaxURL = BASE_URL + 'conversation/remove_conversation';
    
    //$("#dialog-confirm").dialog("close");
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'from_id='+from_id+"&to_id="+to_id,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#conversation_list').html(html); // prikazi rezultat                 
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}

function update_num_online()
{
    var ajaxURL = AJAX_URL + 'update_num_online/';
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        // data: 'id='+id,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                $('#num_online').html(parsed.num_online);                                
            }
            else
            {
                html += "<p><span class='highlight-icon ui-icon ui-icon-info'></span>";      
                html += parsed.msg +"</p>";

                $('#response').show().addClass('ui-state-error ui-corner-all').html(html); 
            }            
        }  
    }); // end AJAX upita 
}



function update_right_part_menu()
{
    var ajaxURL = AJAX_URL + 'update_right_part_menu/';
    
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        // data: 'id='+id,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            //var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                $('#right_part_menu').html(parsed.html);                                
            }
            else
            {
//                html += "<p><span class='highlight-icon ui-icon ui-icon-info'></span>";      
//                html += parsed.msg +"</p>";
//
//                $('#response').show().addClass('ui-state-error ui-corner-all').html(html); 
            }            
        }  
    }); // end AJAX upita 
}

function setPresentIsView(present_id)
{
    var ajaxURL = BASE_URL + 'presents/setPresentIsView';
   
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'present_id='+present_id,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#presents_list').html(html); // prikazi rezultat 
                update_right_part_menu();
                $(document).bind('cbox_closed', function(){
                  location.reload();
                });
            }
//            else
//            {      
//                html += "<p>"+parsed.msg +"</p>";
//                $('#response').show().html(html).delay(2500).hide(500); 
//            }            
        }  
    }); // end AJAX upita
}



function remove_present(present_id)
{
  var ajaxURL = BASE_URL + 'presents/removePresent';
   
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'present_id='+present_id,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                //html += parsed.html; // rezultat HTML 
                //$('#presents_list').html(html); // prikazi rezultat                 
                //location.reload();  
                $('present_'+present_id).hide();
            }
//            else
//            {      
//                html += "<p>"+parsed.msg +"</p>";
//                $('#response').show().html(html).delay(2500).hide(500); 
//            }            
        }  
    }); // end AJAX upita
}


////////////////////////////////////////////////////////////////////////////////
//    SEARCH BOX
////////////////////////////////////////////////////////////////////////////////
// Search Friend
function search_friend(name)
{
    var ajaxURL = BASE_URL + 'friends/serchFriends';
   
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'name='+name,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#friends_list').html(html); // prikazi rezultat               
                
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}


function search_favorite(name)
{
    var ajaxURL = BASE_URL + 'favorites/searchFavorites';
   
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'name='+name,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {
                html += parsed.html; // rezultat HTML 
                $('#favorites_list').html(html); // prikazi rezultat               
                
            }
            else
            {      
                html += "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}


function add_to_spotlight()
{
    var ajaxURL = BASE_URL + 'profile/addToSpotlight';
   
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        //data: 'name='+name,
        cache: false,
        async: false,
        success: function(response){

            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {                
                $('#spotlight').html( parsed.html); // prikazi rezultat   
                html = "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }
            else
            {      
                html = "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}


function update_messages()
{
    var ajaxURL = BASE_URL + 'conversation/getMessages';
    var userFromName = $('#user_from_name').val();
    // Ajax upit
    $.ajax({  
        type: "POST", 
        url: ajaxURL,
        data: 'user_from_name='+userFromName,
        cache: false,
        async: false,
        success: function(response){
            
            
            var parsed = JSON.parse(response);
            var html = '';

            if(parseInt(parsed.ind) == 1)
            {                
                $('#messages_list').html( parsed.html ); // prikazi rezultat   
                //html = "<p>"+parsed.msg +"</p>";
                //$('#response').show().html(html).delay(2500).hide(500); 
            }
            else
            {      
                html = "<p>"+parsed.msg +"</p>";
                $('#response').show().html(html).delay(2500).hide(500); 
            }            
        }  
    }); // end AJAX upita
}
